<template>
  <div class="comment-list">
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
     <commentItem 
      v-for="(item,index) in list"
      :key="index"
      :commentList="item"
      @deleteComment="(item.like_count = $event)"
      @iconComment="(item.is_liking = $event)"
     />
    </van-list>
  </div>
</template>

<script>
import commentItem from './commentItem.vue'
import { getUserComment } from '@/service/getDate'
export default {
  name: 'commentList',
  data() {
    return {
      list: [],
      Clist:[],
      loading: false,
      finished: false,
      offset: null, // 页码 传null则表示从第一页开始加载
      limit: 20, // 每页需要加载的数量
      type: 'a',
    };
  },
  created(){
    this.onLoad()
  },
  props: {
    articleId: {
      type: [Number,String,Object],
      required: true,
    },
    // type: {
    //   type: String,
    //   // 自定义prop数据验证
    //   validator (value) {
    //     return ['a','c'].includes(value)
    //   },
    //   default: 'a'
    // }
  },
  components: {
    commentItem,
  },
  methods: {
    // 获取评论
   async onLoad() {
      try {
        const {data} = await getUserComment({
          type:this.type,
          source: this.articleId,
          offset: this.offset,
          limit: this.limit,
        })
        const {results} = data.data
        this.list = results
        console.log(this.type);
        console.log(this.list);
        this.$emit('commentNum', this.list)
        this.finished = true
      } catch(err) {
        console.log(err);
      }
    },
    
  },

}
</script>

<style>

</style>